package qsl.app.WifiManager;

import java.util.List;

import android.app.Service;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.wifi.ScanResult;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.Binder;
import android.os.IBinder;

public class MainService extends Service {
	WifiManager manager;
	public int wifiState;
	
	private class MainReceiver extends BroadcastReceiver {
		@Override
		public void onReceive(Context context, Intent intent) {
			wifiState = manager.getWifiState();
			sendBroadcast(new Intent(strings.MESSAGE_WIFI_CHANGED));
		}
	}

	@Override
	public void onCreate() {
		manager = (WifiManager)getSystemService(Context.WIFI_SERVICE);
		registerReceiver(new MainReceiver(), new IntentFilter(WifiManager.WIFI_STATE_CHANGED_ACTION));
	}
	
	public WifiInfo getCurrentNetwork() {
		return manager.getConnectionInfo();
	}
	public boolean startScan() {
		return manager.startScan();
	}
	public List<ScanResult> getScanResults() {
		return manager.getScanResults();
	}
	public List<WifiConfiguration> getConfiguredNetworks() {
		return manager.getConfiguredNetworks();
	}
	public boolean setWifiEnabled(boolean enabled) {
		return manager.setWifiEnabled(enabled);
	}

	@Override
	public void onDestroy() {
		stopSelf();
		super.onDestroy();
	}

	public class MainBinder extends Binder {
		public MainService getService() {
			return MainService.this;
		}
	}
	private MainBinder mybinder = new MainBinder();
	
	@Override
	public IBinder onBind(Intent intent) {
		return mybinder;
	}
}
